﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Xml.Serialization;
using Editor.Custom_Controls;
using Editor.Utilities;

namespace Editor.PageControls
{
    public class PageLabel : PageControl<string>
    {
        public int MaxWidth { get; set; }

        public override string NamingPrefix
        {
            get { return "yazı"; }
        }

        public PageLabel()
        {
            this.Dictionary = new SDictionary<string>();
        }

        public override void UpdateInnerControl()
        {
            TransparentLabel transparentLabel = InnerControl as TransparentLabel;

            transparentLabel.Font = new Font("Segoe UI", TextFontSize, 
                FontStyle.Regular, GraphicsUnit.Point);
            transparentLabel.BackColor = BackColor;
            transparentLabel.ForeColor = ForeColor;
            transparentLabel.Location = Location;
            transparentLabel.Text = CurrentElement;
            transparentLabel.Visible = Visible;

            StringFormat sf = new StringFormat(StringFormatFlags.MeasureTrailingSpaces);

            Size = transparentLabel.Size = transparentLabel.CreateGraphics().
                MeasureString(transparentLabel.Text, transparentLabel.Font, 
                MaxWidth, sf).ToSize();
        }

        protected override PropertiesFormBase generatePropertiesForm()
        {
            return new LabelProperties();
        }

        protected override Control generateInnerControl()
        {
            return new TransparentLabel();
        }

        public override object Clone()
        {
            PageLabel newPageLabel = new PageLabel();

            newPageLabel.BackColor = BackColor;
            newPageLabel.ForeColor = ForeColor;
            newPageLabel.Location = Location;
            newPageLabel.MaxWidth = MaxWidth;
            newPageLabel.Name = Name;
            newPageLabel.TextFontSize = TextFontSize;
            newPageLabel.Visible = Visible;
            newPageLabel.Dictionary = Dictionary.Clone() as SDictionary<string>;

            return newPageLabel;
        }
    }
}
